﻿using System.Data;
using System.IO;

namespace Portal.Workflow.Model
{
    public class UserCls
    {
        public string UserId;
        public string LoginName;
        public string Password;
        public string FullName;
        public string Address;
        public string Tel;
        public string Fax;
        public string SessionId;
        
        public string OfficeCode;

        public UserCls()
        {
        }
        
        public UserCls(string Xml)
        {
            Parse(Xml);
        }

        public string GetXml()
        {
            DataSet ds = new DataSet();
            ds.Tables.Add("Data");
            ds.Tables["Data"].Columns.Add("UserId");
            ds.Tables["Data"].Columns.Add("LoginName");
            ds.Tables["Data"].Columns.Add("FullName");
            ds.Tables["Data"].Columns.Add("Password");
            ds.Tables["Data"].Columns.Add("Address");
            ds.Tables["Data"].Columns.Add("Tel");
            ds.Tables["Data"].Columns.Add("Fax");
            ds.Tables["Data"].Columns.Add("SessionId");
            ds.Tables["Data"].Columns.Add("OfficeCode");
            ds.Tables["Data"].Rows.Add(new object[]{
                UserId,LoginName,FullName,Password,Address,Tel,Fax,SessionId,OfficeCode
            });
            return ds.GetXml();
        }

        public void Parse(string Xml)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(new StringReader(Xml));
            if (ds.Tables.Count > 0)
            {
                try
                {
                    UserId = (string)ds.Tables[0].Rows[0]["UserId"];
                }
                catch { }
                try
                {
                    LoginName = (string)ds.Tables[0].Rows[0]["LoginName"];
                }
                catch { }
                try
                {
                    FullName = (string)ds.Tables[0].Rows[0]["FullName"];
                }
                catch { }
                try
                {
                    Password = (string)ds.Tables[0].Rows[0]["Password"];
                }
                catch { }

                try
                {
                    Address = (string)ds.Tables[0].Rows[0]["Address"];
                }
                catch { }

                try
                {
                    Tel = (string)ds.Tables[0].Rows[0]["Tel"];
                }
                catch { }

                try
                {
                    Fax = (string)ds.Tables[0].Rows[0]["Fax"];
                }
                catch { }

                try
                {
                    SessionId = (string)ds.Tables[0].Rows[0]["SessionId"];
                }
                catch { }
                try
                {
                    OfficeCode = (string)ds.Tables[0].Rows[0]["OfficeCode"];
                }
                catch { }
            }
        }
    }
}
